// pages/welcome/welcome.js
import { HTTP } from '../../utils/http.js'
let ajax = new HTTP()
var app = getApp()

Page({
    data: {
        defaultText: '欢迎使用随时体育',
        defaultButton: '开始使用'
    },
    // 是否授权
    getUserInfoTap (event) {
        if (event.detail.userInfo) {
            app.globalData.userInfo = event.detail.userInfo
            wx.setStorageSync("userInfo", event.detail.userInfo)
            let userInfo = app.globalData.userInfo
            let memberid = wx.getStorageSync("memberid")
            // 拒绝之后重发请求
            ajax.request({
                method: "POST",
                url: "member",
                data: {
                    id: memberid,
                    nickname: userInfo.nickName,
                    headimgurl: userInfo.avatarUrl,
                    city: userInfo.city,
                    country: userInfo.country,
                    sex: userInfo.gender
                },
                success: (res) => {
                    
                }
            })
            let flag = wx.getStorageSync("flag")
            let detailid = wx.getStorageSync("detailid")
            if (flag) {
                wx.reLaunch({
                    url: '/pages/live/detail/detail?id=' + detailid,
                })
                wx.setStorageSync("flag", false)
            } else {
                wx.reLaunch({
                    url: '/pages/live/live',
                })
            }
        } else {
            this.setData({
                defaultText: '为保证您的正常使用,请进行授权!',
                defaultButton: '重新授权'
            })
        }
    }
})